package com.cc.alltype;

import java.io.Serializable;

/**
 * 2024年7月29日 07:57:47
 * 后端响应给前端的结果
 */
public class ResponseResult implements Serializable {
    private static final long serialVersionUID = 1L;
    private boolean success;
    private int code;// 错误代码，默认0表示没有错误
    private String msg;
    private Object data;

    //# region 构造方法
    public ResponseResult(){
        this.success = true;
        this.code = 0;
        this.msg = "";
        this.data = null;
    }

    public ResponseResult(Object data){
        this.success = true;
        this.code = 0;
        this.msg = "";
        this.data = data;
    }

    public ResponseResult(String msg){
        this.success = true;
        this.code = 0;
        this.msg = msg;
        this.data = null;
    }

    public ResponseResult(String msg, Object data){
        this.success = true;
        this.code = 0;
        this.msg = msg;
        this.data = data;
    }

    public ResponseResult(boolean success,String msg, Object data){
        this.success = success;
        this.code = 0;
        this.msg = msg;
        this.data = data;
    }

    public ResponseResult(boolean success, int code, String msg, Object data){
        this.success = success;
        this.code = code;
        this.msg = msg;
        this.data = data;
    }
    public static ResponseResult ok(){
        ResponseResult rr = new ResponseResult();
        rr.success = true;
        rr.code = 0;
        rr.msg = "";
        rr.data = null;
        return rr;
    }
    public static ResponseResult ok(String msg){
        ResponseResult rr = new ResponseResult();
        rr.success = true;
        rr.code = 0;
        rr.msg = msg;
        rr.data = null;
        return rr;
    }
    public static ResponseResult ok(Object data){
        ResponseResult rr = new ResponseResult();
        rr.success = true;
        rr.code = 0;
        rr.msg = "";
        rr.data = data;
        return rr;
    }
    public static ResponseResult ok(String msg, Object data){
        ResponseResult rr = new ResponseResult();
        rr.success = true;
        rr.code = 0;
        rr.msg = msg;
        rr.data = data;
        return rr;
    }
    public static ResponseResult error(String msg){
        ResponseResult rr = new ResponseResult();
        rr.success = false;
        rr.code = 0;
        rr.msg = msg;
        rr.data = null;
        return rr;
    }
    public static ResponseResult error(Object data){
        ResponseResult rr = new ResponseResult();
        rr.success = false;
        rr.code = 0;
        rr.msg = "";
        rr.data = data;
        return rr;
    }
    public static ResponseResult error(String msg, Object data){
        ResponseResult rr = new ResponseResult();
        rr.success = false;
        rr.code = 0;
        rr.msg = msg;
        rr.data = data;
        return rr;
    }
    public static ResponseResult error(String msg, int code){
        ResponseResult rr = new ResponseResult();
        rr.success = false;
        rr.code = code;
        rr.msg = msg;
        rr.data = null;
        return rr;
    }
    //# endregion

    //#region getter,setter,toString
    public boolean isSuccess() {
        return success;
    }

    public void setSuccess(boolean success) {
        this.success = success;
    }

    public int getCode() {
        return code;
    }

    public void setCode(int code) {
        this.code = code;
    }

    public String getMsg() {
        return msg;
    }

    public void setMsg(String msg) {
        this.msg = msg;
    }

    public Object getData() {
        return data;
    }

    public void setData(Object data) {
        this.data = data;
    }

    @Override
    public String toString() {
        return "ResponseResult{" +
                "success=" + success +
                ", code=" + code +
                ", msg='" + msg + '\'' +
                ", data=" + data +
                '}';
    }
    //# endregion
}
